package com.itheima.health.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("checkgroup")
//@PreAuthorize("hasRole('ADMIN')")

public class CheckGroupController {

    @Reference
    private CheckGroupService CheckGroupService;

    @GetMapping("findAll")
    @PreAuthorize("hasAuthority('DELETE')")
    public Result findAll(){
        return new Result(true,"查询所有",CheckGroupService.list());
    }

    @PostMapping("findPage")
    public Result findAll(@RequestBody QueryPageBean pageBean){
        PageResult page = CheckGroupService.findPage(pageBean);
        return new Result(true,"查询所有",page);
    }

    @PostMapping("add")
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO){
        return new Result(true,"操作成功",CheckGroupService.saveCheckGroup(checkGroupDTO));
    }
    @DeleteMapping("deleteCheckGroupById/{id}")
    public Result deleteCheckGroupById(@PathVariable int id){
        CheckGroup CheckGroup = new CheckGroup();
        CheckGroup.setId(id);
        CheckGroup.setIs_delete(1);
        return new Result(true,"删除成功",CheckGroupService.updateById(CheckGroup));
    }
    @GetMapping("findCheckItemInfoByGroupId/{id}")
    public Result findCheckItemInfoByGroupId(@PathVariable int id){
        return new Result(true,"",CheckGroupService.findCheckItemInfoByGroupId(id));
    }

}
